using System;
using System.Globalization;

namespace OpenWaves.HtmlEncoding
{
    public class UrlToken : HtmlToken
    {
        private readonly Url url;

        public UrlToken(int startIndex, int endIndex, Url url)
            : base(startIndex, endIndex)
        {
            this.url = url;
        }

        public override void Render(IHtmlWriter writer)
        {
            writer.WriteTag(string.Format(CultureInfo.InvariantCulture, "<a href=\"{0}\">", this.url));

            foreach (var token in Children)
            {
                token.Render(writer);
            }
            writer.WriteTag("</a>");
        }
    }
}